package tp.pr3;

import java.io.FileInputStream;
import java.io.IOException;
import java.util.ArrayList;

import tp.pr3.cityLoader.CityLoaderFromTxtFile;
import tp.pr3.items.CodeCard;
import tp.pr3.items.Fuel;
import tp.pr3.items.Garbage;

public class Main {
	private static final String LINE_SEPARATOR = System
			.getProperty("line.separator");

	/**
	 * Metodo principal del programa. Inicializa los arrays de Places y de
	 * Streets, crea un nuevo objeto RobotEngine (el propio juego) y llama al
	 * metodo startEngine para comenzar la partida
	 */
	public static void main(String[] args) {

		if (args.length == 0) {
			System.err.println("Bad params." + LINE_SEPARATOR
					+ "Usage: java tp.pr3.Main <mapfile>" + LINE_SEPARATOR
					+ LINE_SEPARATOR
					+ "<mapfile> : file with the description of the city.");
			System.exit(1);
		}
		CityLoaderFromTxtFile cityLoader = new CityLoaderFromTxtFile();
		String file = args[0];
		try {

			City city = cityLoader.loadCity((new FileInputStream(file)));
			// Inicializa el robot
			RobotEngine robot = new RobotEngine(city,
					cityLoader.getInitialPlace(), Direction.NORTH);
			
			// Empieza la simulacion
			robot.startEngine();
			System.exit(0);
		} catch (IOException e) {
			System.err.println(Message.ERROR_READING.replace("<file>", file));
			System.exit(2);
		}
		
	}

}
